package com.winner.strategy_pattern.pay;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class PaymentController {

    // 策略 + 工厂 + 模板设计模式 两行代码解决了
    // 根据不同的支付类型来付款
    @PostMapping("/pay")
    public String pay(String paymentType, String goodsId, Double amout){
        PaymentStrategy strategy = PaymentFactory.getInvokeStrategy("ALI_PAY");
        strategy.pay(1L, 100);
        strategy.BBB("支付宝调用BBB接口");

        PaymentStrategy strategy2 = PaymentFactory.getInvokeStrategy("WECHAT_PAY");
        strategy2.pay(2L, 200);
//        invokeStrategy2.BBB("调用微信没有的BBB方法");  这里如果微信调用BBB方法就会抛出异常UnsupportedOperationException
        return "success";
    }

}
